package vip.zcn.mrn.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import vip.zcn.mrn.service.LoginService;

/**
 * 登录控制器类
 * 提供基于用户名和手机号的登录接口
 * @author 张灿能
 */
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class LoginController {
    private final LoginService loginService;

    /**
     * 通过用户名登录
     * @param username 用户名
     * @param password 密码
     * @return 登录结果信息
     */
    @PostMapping("/login/username")
    public String loginByUsername(@RequestParam String username, @RequestParam String password) {
        return loginService.loginByUsername(username, password) ? "登录成功" : "登录失败";
    }

    /**
     * 通过手机号登录
     * @param phone 手机号
     * @param password 密码
     * @return 登录结果信息
     */
    @PostMapping("/login/phone")
    public String loginByPhone(@RequestParam String phone, @RequestParam String password) {
        return loginService.loginByPhone(phone, password) ? "登录成功" : "登录失败";
    }
}